/**
 * 
 */
package com.alstudio.module.xmpp.protocol.xmpp.parser.iq.props;

import java.util.ArrayList;

import com.alstudio.module.xmpp.protocol.xmpp.ALXmppEventListener;
import com.alstudio.module.xmpp.protocol.xmpp.packact.ALIQ;
import com.alstudio.module.xmpp.protocol.xmpp.parser.iq.ALBaseIQParser;
import com.alstudio.module.xmpp.protocol.xmpp.parser.iq.IQParseEventHandler.IQXmlParseEventCallback;
import com.alstudio.pojo.module.local.Prop;
import com.alstudio.utils.formater.numeric.ALNumericUtils;
import com.alstudio.utils.log.ALLog;

/**
 * 道具价格解析
 * 
 * @author alonso lee
 * 
 */
public class PropsPriceParesr extends ALBaseIQParser implements
		IQXmlParseEventCallback {

	private Prop prop = null;
	private Prop curProp = null;
	private int propBuyCount = 0;
	private ArrayList<Prop> proplist = new ArrayList<Prop>();

	@Override
	public void parseIQPackage(ALIQ packact, String stream,
			ALXmppEventListener listener) throws Exception {
		// TODO Auto-generated method stub
		code = 0;
		prop = null;
		curProp = null;
		proplist = null;
		proplist = new ArrayList<Prop>();
		propBuyCount = 0;
		mListener = listener;
		startParse(packact, stream, this);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.alstudio.module.xmpp.protocol.xmpp.parser.iq.IQParseEventHandler.
	 * IQXmlParseEventCallback#processErrorStartTag(java.lang.String)
	 */
	@Override
	public void processErrorStartTag(String tag) {
		// TODO Auto-generated method stub
		if (tag.equals(ERROR_CODE_TAG)) {
			code = ALNumericUtils.parseInt(getAttValue("code"), 0);
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.alstudio.module.xmpp.protocol.xmpp.parser.iq.IQParseEventHandler.
	 * IQXmlParseEventCallback#processSetStartTag(java.lang.String)
	 */
	@Override
	public void processSetStartTag(String tag) {
		// TODO Auto-generated method stub

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.alstudio.module.xmpp.protocol.xmpp.parser.iq.IQParseEventHandler.
	 * IQXmlParseEventCallback#processGetStartTag(java.lang.String)
	 */
	@Override
	public void processGetStartTag(String tag) {
		// TODO Auto-generated method stub

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.alstudio.module.xmpp.protocol.xmpp.parser.iq.IQParseEventHandler.
	 * IQXmlParseEventCallback#processResultStartTag(java.lang.String)
	 */
	@Override
	public void processResultStartTag(String tag) {
		// TODO Auto-generated method stub
		if (tag.equals("buycount")) {
			propBuyCount = ALNumericUtils.parseInt(readText(), 0);
		} else if (tag.equals("mineprops")) {
			// 我的道具
			curProp = new Prop();
			curProp.setProp(getAttValue("props"));
			curProp.setPropLevel(ALNumericUtils.parseInt(getAttValue("level"),
					0));
			curProp.setPropStartTime(ALNumericUtils.parseInt(
					getAttValue("starttime"), 0));
			curProp.setPropEndTime(ALNumericUtils.parseInt(
					getAttValue("endtime"), 0));
			curProp.setPropPeople(getAttValue("people"));

		} else if (tag.equals("props")) {

			prop = new Prop();
			prop.setId(getAttValue("id"));
			prop.setProp(getAttValue("props"));
			prop.setPropName(getAttValue("propsname"));
			prop.setPropDuration(ALNumericUtils.parseInt(
					getAttValue("duration"), 0));
			prop.setPropPeople(getAttValue("people"));
			prop.setPropGold(getAttValue("gold"));
			prop.setJindou(getAttValue("jindou"));
			prop.setPropVipGold(getAttValue("vipgold"));
			prop.setPropItunesid(getAttValue("itunesid"));
			prop.setPropRmb(getAttValue("rmb"));
			prop.setPropDollar(getAttValue("dollar"));
			prop.setPropSave(ALNumericUtils.parseInt(getAttValue("save"), 0));

			proplist.add(prop);

		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.alstudio.module.xmpp.protocol.xmpp.parser.iq.IQParseEventHandler.
	 * IQXmlParseEventCallback#processEndTag(java.lang.String)
	 */
	@Override
	public void processEndTag(String tag) {
		// TODO Auto-generated method stub

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.alstudio.module.xmpp.protocol.xmpp.parser.iq.IQParseEventHandler.
	 * IQXmlParseEventCallback#processStartDocument()
	 */
	@Override
	public void processStartDocument() {
		// TODO Auto-generated method stub

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.alstudio.module.xmpp.protocol.xmpp.parser.iq.IQParseEventHandler.
	 * IQXmlParseEventCallback#processEndDocument()
	 */
	@Override
	public void processEndDocument() {
		// TODO Auto-generated method stub
		onCallback();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.alstudio.module.xmpp.protocol.xmpp.parser.iq.ALBaseIQParser#onCallback
	 * ()
	 */
	@Override
	public void onCallback() {
		// TODO Auto-generated method stub
		if (mListener != null) {
			mListener.onGetCurrentBuyPropsInfoResult(code, proplist,
					curProp, propBuyCount);
			ALLog.d("回调我的道具结果 " + code);
		}
	}

}
